﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace littleAdminHelper
{
    class SimpleCrypto
    {

        // Random Chars is the Number of Random Charracters added at the start and the end of the Password
        public static int randomchars=5;

        // Ceasar Encryption add Number to current Character Value
        public static int chars=4;

        public static String decrypt(String encryptedText){
            String decryptedString="";
            Random random = new Random();

            char[] text = encryptedText.ToCharArray();
            for (int i = 0; i < text.Length; i++)
            {
                text[i] = (char) (text[i] + chars%254);
            }
            // add Random chars to start and End

            for (int i = 0; i < text.Length + 2 * randomchars; i++)
            {
                if (i < randomchars || i > text.Length + randomchars - 1)
                {
                    decryptedString += "" + (char)random.Next(0, 256);
                }
                else
                {
                    decryptedString += "" + text[i - (randomchars)];
                }
            }
            return decryptedString;

            
        }

        public static String encrypt(String cryptedString)
        {
            try {
            String encryptedString = "";
            char[] text = cryptedString.Substring(randomchars,cryptedString.Length-2*randomchars).ToCharArray();

            for (int i = 0; i < text.Length; i++)
            {
                encryptedString += "" + (char)(text[i] - chars % 254);
            }

            return encryptedString;

            }
            catch (Exception e)
            {
                return null;
            }
            

        }
            


    }
}
